package commands;

import utils.CommandStack;
import utils.EditorContext;

public class UndoCommand extends Command {


    public UndoCommand(EditorContext context) {
        super(context);
    }

    @Override
    public void execute() {
        context.setSavingState(EditorContext.SavingState.ToSave);
        if(CommandStack.getInstance().size() == 1){
            throw new UnsupportedOperationException("Undo operation is not supported for LoadCommand.");
        }
        else{
            Command command = CommandStack.getInstance().remove(CommandStack.getInstance().size() - 1);
            CommandStack.setRedoCommand(command);
            context.setContent(CommandStack.getInstance().get(CommandStack.getInstance().size() - 1).getContext().getContent());
        }
    }

}
